package com.yamibuy.ec.resource.aws;

import com.amazonaws.auth.EnvironmentVariableCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Aws配置
 *
 * @author: damon.li
 * @version: 2021年02月23日 8:54
 */
@Configuration
public class AwsConfig {

	@Bean
	public AmazonS3 s3Client(@Value("${aws.s3.regions}") String regions) {
		/**
		 * 环境变量读取key和secret 方便部署,
		 * AWS_ACCESS_KEY_ID = AKIAV5PTJPXHPWF2PMMC
		 * AWS_SECRET_ACCESS_KEY = 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
		 * AWS_REGION = us-west-2
		 */
		EnvironmentVariableCredentialsProvider environmentVariableCredentialsProvider = new EnvironmentVariableCredentialsProvider();
		return AmazonS3ClientBuilder.standard().withRegion(Regions.fromName(regions)).withCredentials(environmentVariableCredentialsProvider).build();
	}
}
